﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace John
{
    public partial class qglist : System.Web.UI.Page
    {

        public string strPID = "-1";
        public string strPBewrite = "";//产品简介  
        public string strPUseMode = "";//使用说明
        public string strPValidity = "";
        //有效期

        public string strBuy = "";//打印留言询价 或 没有存货
        public string company;
        public string word;
        public string sitename;
        public string name;


        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    string strID = Request.QueryString["id"].ToString();
                    strID = CleanString.htmlInputText(strID);

                    DBConn myDB = new DBConn();
                    string sql = "select * from qqproduct where qID=" + strID;
                    SqlDataReader dr;
                    try
                    {
                        dr = myDB.getDataReader(sql);
                    }
                    catch
                    {
                        Response.Write("<script>");
                        Response.Write("alert('没有这个产品信息!!!');");
                        Response.Write("</script>");
                        Response.Redirect("Default.aspx");
                        return;
                    }

                    if (dr.Read())
                    {
                        ViewState["qlb"] = dr["qlb"].ToString();
                    }
                    else
                    {
                        Response.Write("<script>");
                        Response.Write("alert('没有这个产品信息!!!');");
                        Response.Write("</script>");
                        dr.Close();
                        myDB.Close();
                        Response.Redirect("Default.aspx");
                        return;
                    }
                    dr.Close();
                    myDB.Close();

                    ViewState["ID"] = strID;


                }
                hotdata();
                newdata();
                DHData();
                PData();
                comp();
                getNewDataList();//最新上架
                qqDataList();//求购
                zsDataList();
                upphb();
            }
        }
        private void upphb()
        {
            string strID = ViewState["ID"].ToString();
            DBConn mydb = new DBConn();
            string sql = "update qqproduct set phb=(select phb from qqproduct where qid=" + strID + ") +1 where qid=" + strID;
            mydb.Update(sql);
            mydb.Close();
        }

        private void zsDataList()//创业
        {
            DBConn mydb = new DBConn();
            string sql = "select id,zname,zimg from zhaoshang where hyname='" + Label5.Text + "' order by id desc";
            DataList2.DataSource = mydb.getDataReader(sql);
            DataList2.DataBind();
            mydb.Close();
        }
        private void PData()//显示相应产品信息
        {
            string strID = ViewState["ID"].ToString();

            DBConn myDB = new DBConn();
            string sql = "select * from qqproduct where qID=" + strID;
            SqlDataReader dr = myDB.getDataReader(sql);
            if (dr.Read())
            {
                lblPName.Text = dr["qname"].ToString();
                sitename = dr["qname"].ToString();
                lblPNPrice.Text = dr["qjiage"].ToString();
                strPBewrite = dr["qjs"].ToString();
                Label1.Text = dr["qxh"].ToString();
                Label2.Text = dr["qsl"].ToString();
                Label5.Text = dr["uname"].ToString();
                name = dr["uname"].ToString();
                word = dr["qid"].ToString();
            }
            dr.Close();
            myDB.Close();
        }
        private void comp()//显示相应产品信息
        {
            DBConn myDB = new DBConn();
            string sql = "select gsname,zsname,gsleixing,gsdiqu from Muser where hyname='" + Label5.Text + "'";
            SqlDataReader dr = myDB.getDataReader(sql);
            if (dr.Read())
            {
                company = dr["gsname"].ToString();
                Label3.Text = dr["gsdiqu"].ToString();
                Label4.Text = dr["zsname"].ToString();
                Label6.Text = dr["gsleixing"].ToString();
            }
            dr.Close();
            myDB.Close();
        }
        private void getNewDataList()//最新上架
        {
            try
            {
                string uName = Label5.Text;
                NDataList.DataSource = UserScreenControl.GetNewDataList("qglist", uName);
                NDataList.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
        private void qqDataList()//求购
        {
            DBConn mydb = new DBConn();
            string sql = "select qid,qname from qqproduct where uname='" + Label5.Text + "' order by qID desc";
            DataList1.DataSource = mydb.getDataReader(sql);
            DataList1.DataBind();
            mydb.Close();
        }

        private void DHData()//导航条设置
        {
            string strCID = ViewState["qlb"].ToString();

            if (ViewState["qlb"] == null || ViewState["qlb"].ToString() == String.Empty)
            {
                lblDaohang.Text = "所有产品";
            }
            else
            {
                DBConn myDB = new DBConn();
                string sql = "select * from Category where CID=" + strCID;
                SqlDataReader dr = myDB.getDataReader(sql);
                if (dr.Read())
                {
                    lblDaohang.Text = dr["CName"].ToString();
                }
                dr.Close();
                myDB.Close();
            }
        }

        private void hotdata()//推荐求购
        {
            DBConn mydb = new DBConn();
            string sql = "select top 10 * from qqproduct where qtj=1 ";
            HotRepeater.DataSource = mydb.getDataReader(sql);
            HotRepeater.DataBind();
            mydb.Close();
        }
        private void newdata()//最新求购
        {
            DBConn mydb = new DBConn();
            string sql = "select top 10 * from qqproduct order by qid desc";
            Repeater1.DataSource = mydb.getDataReader(sql);
            Repeater1.DataBind();
            mydb.Close();

        }

    }
}
